"""dailyfresh URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/2.2/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path, re_path

urlpatterns = [
    path('admin/', admin.site.urls),
]

from bg import views as bg_views
from ft import views as ft_views

#后台管理url
urlpatterns += [
    path('bg/index/', bg_views.index),  # 首页
    path('bg/register/', bg_views.register),  # 注册
    path('bg/login/', bg_views.login),  # 登录
    path('bg/logout/', bg_views.logout),  # 登出
    path('bg/store/', bg_views.store),  # 店铺管理
    path('bg/goods/list/', bg_views.goods_list),  # 商品列表
    path('bg/goods/add/', bg_views.goods_add),  # 商品新增

]
#前台管理url
urlpatterns += [
    path('ft/api/goods/', ft_views.api_goods),  # api:查询商品信息
    path('ft/api/goods/new/', ft_views.api_goods_new),  # api:查询新品推荐
    path('ft/goods/list/', ft_views.goods_list),  # 商品列表页，ajax
    path('ft/goods/list2/', ft_views.goods_list2),  # 商品列表页，vue
    path('ft/login/', ft_views.login),  # 登录
    path('ft/register/', ft_views.register),  # 注册
    path('', ft_views.index),  # 首页
    path('ft/api/more/', ft_views.More.as_view()),  # 查看更多
    path('ft/detail/', ft_views.detail),  # 详情页
    path('ft/user/center/', ft_views.user_center),  # 用户中心页
    path('ft/user/center/address/add/', ft_views.user_center_address_add),  # 用户中心页-地址新增
    path('ft/user/center/address/edit/', ft_views.user_center_address_edit),  # 用户中心页-地址编辑
    path('ft/cart/add/', ft_views.cart_add),  # 加入购物车
    path('ft/cart/list/', ft_views.cart_list),  # 购物车列表
    path('ft/order/place/', ft_views.order_place),  # 提交订单页面
    path('ft/order/add/', ft_views.order_add),  # 订单新增
    path('ft/order/pay/', ft_views.order_pay),  # 订单支付
    path('ft/pay/result/', ft_views.pay_result),  # 订单支付结果

    path('ft/register2/', ft_views.register2),  # 注册
    path('ft/register2/phone/code/', ft_views.register2_phone_code),  # 发送验证码

    path('ft/api/goods2/', ft_views.GoodsView.as_view()),  # goods api  查集合
    re_path('ft/api/goods2/(?P<pk>\d+)/', ft_views.GoodsView.as_view()),  # goods api  删，改，查的那个
]
#测试
urlpatterns += [
    path('test1/', bg_views.test1),  # 制作接口
    path('test2/', bg_views.test2),  # vue
    path('test3/fbv/', ft_views.fbv),  # 函数式视图
    path('test3/cbv/', ft_views.CBV.as_view()),  # 类式视图
    path('test7/send/email/', bg_views.test7_send_email),  # 缓存路由
    path('test7/send/message/', bg_views.test7_send_message),  # 缓存路由

    path('test8/task/', bg_views.test8_task),  # 模拟一个耗时的任务
    path('test8/task1/', bg_views.test8_task1),  # 模拟一个耗时的任务
]

from rest_framework.routers import DefaultRouter

# 创建drf路由
dr = DefaultRouter()
# 注册路由
dr.register("rest/goods", ft_views.GoodsViewSet)
# 拼接到总路由中
urlpatterns += dr.urls
